<!DOCTYPE html>
<html>
<head>
  <script>
  var query = new URLSearchParams(window.location.search.slice(1));
  if (!query.has('random')) {
    query.set('random', 'true')
    window.location.search = '?' + query.toString()
  }
</script>
    <meta charset="UTF-8">
    <title>Jasmine Spec Runner</title>
    <% for (var i = 0; i < htmlWebpackPlugin.options.jasmineCssFiles.length; i++) { %>
    <link rel="stylesheet" href="<%= htmlWebpackPlugin.options.jasmineCssFiles[i] %>"/>
    <% } %>

    <script>
      var OriginalXHRClass = XMLHttpRequest;
      var oldManifestValue = null;

      function checkUpdates(url) {
        var xhr = new OriginalXHRClass();
        xhr.open('GET', url + '?' + new Date().getTime());
        xhr.onreadystatechange = function () {
          if (xhr.readyState === XMLHttpRequest.DONE) {
            if (xhr.status === 200) {
              var json = JSON.parse(xhr.responseText)
              if (oldManifestValue == null) {
                oldManifestValue = json.hash;
                return;
              } else if (oldManifestValue != json.hash) {
                window.location.reload(true)
              }
            }
          }
        };
        xhr.send();
      }

      if (window.location.search.indexOf('no_hot_reload') === -1) {
        setInterval(function () {
          checkUpdates('/go/assets/webpack/manifest.json')
        }, 1000);
      }
    </script>

    <% for (var i = 0; i < htmlWebpackPlugin.options.jasmineJsFiles.length; i++) { %>
    <script src="<%= htmlWebpackPlugin.options.jasmineJsFiles[i] %>"></script>
    <% } %>
</head>
<body></body>
</html>
